package 反射.T7;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.lang.reflect.Method;
import java.util.List;

public class T7 {

    public static void main(String[] args) throws Exception{

        List<String> lines = FileUtils.readLines(new File("反射/T7/CatData.txt"));
        String name = lines.get(0).split(" ")[1].split("=")[1].replace("‘", "").replace("’", "");
        int age = Integer.parseInt(lines.get(0).split(" ")[2].split("=")[1]);

        Class<?> aClass = Class.forName(lines.get(0).split(" ")[0]);
        Object obj = aClass.newInstance();  //对象

        Method setName = aClass.getDeclaredMethod("setName", String.class);
        Method setAge = aClass.getDeclaredMethod("setAge", int.class);

        setName.setAccessible(true);
        setAge.setAccessible(true);
        setName.invoke(obj,name);
        setAge.invoke(obj,age);

        System.out.println(obj);

    }
}
